<template>
    <div>
        <TitleBar class="absolute top-0 left-0 w-[450px]">设备统计</TitleBar>
        <img class="absolute left-[18px] top-[60px] h-[72px] w-[72px]" :src="require('./assets/doorDevice.svg')"
             alt="" />
        <div class="absolute left-[18px] top-[140px] h-[20px] w-[72px] value">{{ total.rkenum ? total.rkenum : 0 }}
        </div>
        <div class="absolute left-[30px] top-[164px] h-[20px] w-[48px] title">门禁设备
        </div>
        <img class="absolute left-[130px] top-[60px] h-[72px] w-[72px]" :src="require('./assets/vehicle.svg')"
             alt="" />
        <div class="absolute left-[130px] top-[140px] h-[20px] w-[72px] value">{{total.barrierGateNum ? total.barrierGateNum : 0}}
        </div>
        <div class="absolute left-[142px] top-[164px] h-[20px] w-[48px] title">车辆道闸
        </div>
        <img class="absolute left-[242px] top-[60px] h-[72px] w-[72px]" :src="require('./assets/camera.svg')" 
             alt="" />
        <div class="absolute left-[242px] top-[140px] h-[20px] w-[72px] value">{{total.cameraNum ? total.cameraNum : 0}}
        </div>
        <div class="absolute left-[254px] top-[164px] h-[20px] w-[48px] title">摄像头
        </div>
        <img class="absolute left-[354px] top-[60px] h-[72px] w-[72px]" :src="require('./assets/otherVideo.svg')"
             alt="" />
        <div class="absolute left-[354px] top-[140px] h-[20px] w-[72px] value">{{total.otherNum ? total.otherNum : 0}}
        </div>
        <div class="absolute left-[366px] top-[164px] h-[20px] w-[48px] title">其他视频
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { getDeviceSum } from './api.js'
import TitleBar from '../components/TitleBar.vue'
export default defineComponent({
    components: { TitleBar },
    inject: ['villageId'],
    data() {
        return {
            total: {
                barrierGateNum: '',
                cameraNum: '',
                otherNum: '',
                rkenum: ''
            }
        }
    },
    mounted() {
        this.setIntervalTotalFn()
    },
    destroyed() {
        clearInterval(this.timer);
        this.timer = null;
        this.myCharts && this.myCharts.dispose()
    },
    methods: {
        setIntervalTotalFn() {
            const villageId = this.villageId
            if (villageId) {
                this.getDeviceStatistic(villageId);
                this.timer = null;
                this.timer = setInterval(() => {
                    this.getDeviceStatistic(villageId);
                }, 20000);
            }
        },
        getDeviceStatistic(villageId) {
            getDeviceSum({ id: villageId }).then(res => {
                if (res.success) {
                    this.total = res.data
                }
            })
        }
    }
})

</script>

<style scoped lang="scss">
.value {
    font-family: 'OPPOSans';
    font-style: normal;
    font-weight: bold;
    font-size: 20px;
    line-height: 20px;
    /* identical to box height, or 100% */

    text-align: center;
    font-feature-settings: 'tnum' on, 'lnum' on;

    color: #E0F7FF;

    text-shadow: 0px 4px 6px rgba(255, 255, 255, 0.4);
}

.title {
    font-family: 'OPPOSans';
    font-style: normal;
    font-weight: 400;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    font-feature-settings: 'tnum' on, 'lnum' on;

    color: rgba(224, 247, 255, 0.8);
}
</style>